perm filename MOVE.LSP[F81,JMC] blob
sn#629508 filedate 1981-12-16 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 move.lsp[f81,jmc] Routines for moving objects from pile to pile
C00004 ENDMK
Cā;
;;;move.lsp[f81,jmc] Routines for moving objects from pile to pile
;;; These routines move objects from one
;;; pile to another and (we hope) can be used for any kind of
;;; solitaire including games like nim and Tower of Hanoi or for
;;; the simulation of systems with movable physical objects.
;;; Our intent is that the piles are named by atoms, and the arguments
;;; x and y are the names of the piles.
(defun move (xx yy n) ; moves n objects from pile xx to pile yy
(prog (z)
(if (lessp (length (eval xx)) n)
(return (list 'too_short xx)))
(setq z (iseg (eval xx) n))
(set xx (remove (eval xx) n))
(set yy (append z (eval yy)))
(return 'move_wins)
))
;;; There will be bugs if xx and yy are used as names of piles.
;;; Perhaps many programs will use gensyms.
;
;;; The initial n elements of the list u.
(defun iseg (u n) (if (= n 0) nil (cons (car u) (iseg (cdr u) (sub1 n)))))
;
;;; What's left of u after the initial n element are removed.
(defun remove (u n) (if (= n 0) u (remove (cdr u) (sub1 n))))